/*
 * EntradaAtestadoMedico2.java
 *
 * Created on 15 de Dezembro de 2007, 20:36
 */

package erreAga.view.atestadoMedico;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import erreAga.dao.DaoException;
import erreAga.eb.AtestadoMedico;
import erreAga.service.ErreAgaService;
import erreAga.service.impl.ErreAgaServiceImpl;

/**
 *
 * @author Danilo Carlos
 */
public class EntradaAtestadoMedico2 extends javax.swing.JFrame {

  /**
   *
   */
  private static final long serialVersionUID = 3867735456812841503L;

  /** Creates new form EntradaAtestadoMedico2 */
  public EntradaAtestadoMedico2() {
    initComponents();
  }

  /**
   * This method is called from within the constructor to initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is always
   * regenerated by the Form Editor.
   */
  // <editor-fold defaultstate="collapsed" desc=" C�digo Gerado
  // ">//GEN-BEGIN:initComponents
  private void initComponents() {
    labelAtestadoMedico = new javax.swing.JLabel();
    jSeparator1 = new javax.swing.JSeparator();
    labelFuncionario = new javax.swing.JLabel();
    fieldFuncionario = new javax.swing.JTextField();
    labelMatricula = new javax.swing.JLabel();
    fieldMatricula = new javax.swing.JTextField();
    jSeparator2 = new javax.swing.JSeparator();
    labelInicio = new javax.swing.JLabel();
    fieldInicio = new javax.swing.JTextField();
    labelFim = new javax.swing.JLabel();
    fieldFim = new javax.swing.JTextField();
    jSeparator3 = new javax.swing.JSeparator();
    labelMotivo = new javax.swing.JLabel();
    jScrollPane1 = new javax.swing.JScrollPane();
    textAreaMotivo = new javax.swing.JTextArea();
    buttonCadastrar = new javax.swing.JButton();
    buttonCancelar = new javax.swing.JButton();

    setResizable(false);
    labelAtestadoMedico.setText("Entrada de Atestado M\u00e9dico");

    labelFuncionario.setText("Funcion\u00e1rio:");

    labelMatricula.setText("Matr\u00edcula:");

    labelInicio.setText("In\u00edcio:");

    labelFim.setText("Fim:");

    labelMotivo.setText("Motivo:");

    textAreaMotivo.setColumns(20);
    textAreaMotivo.setRows(5);
    jScrollPane1.setViewportView(textAreaMotivo);

    buttonCadastrar.setText("Cadastrar");
    buttonCadastrar.addActionListener(new java.awt.event.ActionListener() {

      public void actionPerformed(java.awt.event.ActionEvent evt) {
        buttonCadastrarActionPerformed(evt);
      }
    });

    buttonCancelar.setText("Cancelar");
    buttonCancelar.addActionListener(new java.awt.event.ActionListener() {

      public void actionPerformed(java.awt.event.ActionEvent evt) {
        buttonCancelarActionPerformed(evt);
      }
    });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
        getContentPane());
    getContentPane().setLayout(layout);
    layout
        .setHorizontalGroup(layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addGroup(
                        layout
                            .createParallelGroup(
                                javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jSeparator2,
                                javax.swing.GroupLayout.DEFAULT_SIZE, 336,
                                Short.MAX_VALUE)
                            .addComponent(jSeparator1,
                                javax.swing.GroupLayout.Alignment.TRAILING,
                                javax.swing.GroupLayout.DEFAULT_SIZE, 336,
                                Short.MAX_VALUE)
                            .addComponent(labelAtestadoMedico,
                                javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(
                                layout
                                    .createSequentialGroup()
                                    .addGroup(
                                        layout
                                            .createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(labelFuncionario)
                                            .addComponent(labelMatricula))
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(
                                        layout
                                            .createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(
                                                fieldMatricula,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                147,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(
                                                fieldFuncionario,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                265,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(
                                layout
                                    .createSequentialGroup()
                                    .addGap(19, 19, 19)
                                    .addComponent(labelInicio)
                                    .addGap(15, 15, 15)
                                    .addComponent(fieldInicio,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        88,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(23, 23, 23)
                                    .addComponent(labelFim)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(fieldFim,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        92,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jSeparator3,
                                javax.swing.GroupLayout.DEFAULT_SIZE, 336,
                                Short.MAX_VALUE)
                            .addGroup(
                                layout.createSequentialGroup().addComponent(
                                    labelMotivo).addGap(15, 15, 15)
                                    .addComponent(jScrollPane1,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        285, Short.MAX_VALUE))
                            .addGroup(
                                javax.swing.GroupLayout.Alignment.TRAILING,
                                layout
                                    .createSequentialGroup()
                                    .addComponent(buttonCancelar)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(buttonCadastrar)))
                    .addContainerGap()));
    layout.setVerticalGroup(layout.createParallelGroup(
        javax.swing.GroupLayout.Alignment.LEADING).addGroup(
        layout.createSequentialGroup().addContainerGap().addComponent(
            labelAtestadoMedico).addPreferredGap(
            javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(
            jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10,
            javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(
            javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(
            layout.createParallelGroup(
                javax.swing.GroupLayout.Alignment.BASELINE).addComponent(
                labelFuncionario).addComponent(fieldFuncionario,
                javax.swing.GroupLayout.PREFERRED_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE,
                javax.swing.GroupLayout.PREFERRED_SIZE)).addPreferredGap(
            javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(
            layout.createParallelGroup(
                javax.swing.GroupLayout.Alignment.BASELINE).addComponent(
                labelMatricula).addComponent(fieldMatricula,
                javax.swing.GroupLayout.PREFERRED_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE,
                javax.swing.GroupLayout.PREFERRED_SIZE)).addPreferredGap(
            javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(
            jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10,
            javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(
            javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(
            layout.createParallelGroup(
                javax.swing.GroupLayout.Alignment.BASELINE).addComponent(
                labelFim).addComponent(fieldInicio,
                javax.swing.GroupLayout.PREFERRED_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE,
                javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(fieldFim,
                javax.swing.GroupLayout.PREFERRED_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE,
                javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(
                labelInicio)).addGap(18, 18, 18).addComponent(jSeparator3,
            javax.swing.GroupLayout.PREFERRED_SIZE, 10,
            javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(
            javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(
            layout.createParallelGroup(
                javax.swing.GroupLayout.Alignment.LEADING).addComponent(
                labelMotivo).addComponent(jScrollPane1,
                javax.swing.GroupLayout.PREFERRED_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE,
                javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(18, 18, 18)
            .addGroup(
                layout.createParallelGroup(
                    javax.swing.GroupLayout.Alignment.BASELINE).addComponent(
                    buttonCadastrar).addComponent(buttonCancelar))
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
                Short.MAX_VALUE)));
    pack();
  }// </editor-fold>//GEN-END:initComponents

  private void buttonCancelarActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_buttonCancelarActionPerformed
  // TODO adicione seu c�digo de manipula��o aqui:
    // botao de cancelar clicado
    this.setVisible(false);
  }// GEN-LAST:event_buttonCancelarActionPerformed

  private void buttonCadastrarActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_buttonCadastrarActionPerformed
  // TODO adicione seu c�digo de manipula��o aqui:



    ErreAgaService erreAgaService = new ErreAgaServiceImpl();

    AtestadoMedico at = new AtestadoMedico();


    SimpleDateFormat formatador = new SimpleDateFormat("dd/mm/yy");


    try {
      at.setDataFim(formatador.parse(this.fieldFim.getText()));
      at.setDataInicio(formatador.parse(this.fieldInicio.getText()));
    } catch (ParseException e) {

      e.printStackTrace();
    }


    try {
      at.setFuncionario(erreAgaService.searchFuncionarioByNome(this.fieldFuncionario.getText()));
    } catch (DaoException e) {

      e.printStackTrace();
    }




    at.setMotivo(this.textAreaMotivo.getText());



    try {
      erreAgaService.saveAtestadoMedico(at);
    } catch (DaoException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }



  }// GEN-LAST:event_buttonCadastrarActionPerformed

  /**
   * @param args
   *          the command line arguments
   */
  /*
   * public static void main(String args[]) {
   * java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new
   * EntradaAtestadoMedico2().setVisible(true); } }); }
   */
  // Declara��o de vari�veis - n�o modifique//GEN-BEGIN:variables
  private javax.swing.JButton buttonCadastrar;
  private javax.swing.JButton buttonCancelar;
  private javax.swing.JTextField fieldFim;
  private javax.swing.JTextField fieldFuncionario;
  private javax.swing.JTextField fieldInicio;
  private javax.swing.JTextField fieldMatricula;
  private javax.swing.JScrollPane jScrollPane1;
  private javax.swing.JSeparator jSeparator1;
  private javax.swing.JSeparator jSeparator2;
  private javax.swing.JSeparator jSeparator3;
  private javax.swing.JLabel labelAtestadoMedico;
  private javax.swing.JLabel labelFim;
  private javax.swing.JLabel labelFuncionario;
  private javax.swing.JLabel labelInicio;
  private javax.swing.JLabel labelMatricula;
  private javax.swing.JLabel labelMotivo;
  private javax.swing.JTextArea textAreaMotivo;
  // Fim da declara��o de vari�veis//GEN-END:variables

}
